Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Fixturify is an npm package that allows you to create and manipulate file system fixtures programmatically. It is particularly useful for testing purposes, where you need to set up a specific file system state before running tests.
Create File System Fixtures
This feature allows you to create a directory structure with files and content programmatically. The `writeSync` method writes the specified files and directories to the file system.
const fixturify = require('fixturify');
const files = {
'index.js': 'console.log("Hello, world!");',
'lib': {
'module.js': 'module.exports = {};'
}
};
fixturify.writeSync('my-fixture', files);
Read File System Fixtures
This feature allows you to read a directory structure and its contents into a JavaScript object. The `readSync` method reads the specified directory and returns an object representing the file system structure.
const fixturify = require('fixturify');
const files = fixturify.readSync('my-fixture');
console.log(files);
Update File System Fixtures
This feature allows you to update an existing directory structure with new files or changes to existing files. The `writeSync` method can be used to overwrite or add new files to the specified directory.
const fixturify = require('fixturify');
const updates = {
'index.js': 'console.log("Updated content");',
'lib': {
'newModule.js': 'module.exports = { new: true };'
}
};
fixturify.writeSync('my-fixture', updates);
Mock-fs is a package that allows you to mock the file system in Node.js. It is useful for testing purposes where you need to simulate different file system states. Unlike fixturify, which creates real files and directories, mock-fs creates an in-memory file system.
Memfs is a package that provides an in-memory file system that can be used for testing and other purposes. It is similar to mock-fs in that it does not create real files on the disk, but instead simulates a file system in memory. This can be useful for performance reasons and for tests that should not affect the real file system.
Fs-extra is a package that extends the native Node.js file system module with additional methods for working with the file system. It includes methods for copying, moving, and removing files and directories, as well as reading and writing JSON files. While it does not provide the same fixture creation capabilities as fixturify, it offers a wide range of file system utilities.
Convert JSON objects into directory structures on the file system, and back again. This package is primarily useful for writing tests.
yarn add fixturify
const fs = require('fs')
const fixturify = require('fixturify')
const obj = {
'foo.txt': 'foo.txt contents',
'subdir': {
'bar.txt': 'bar.txt contents'
}
}
fixturify.writeSync('testdir', obj) // write it to disk
fixturify.readSync('testdir') // => deep-equals obj
fixturify.readSync('testdir', { globs: ['foo*'] }) // glob support
// => { foo.txt: 'foo.text contents' }
fixturify.readSync('testdir', { ignore: ['foo*'] }) // glob support
// => { subdir: { bar.txt: 'bar.text contents' } }
fixturify.writeSync('testDir', {
'subdir': { 'bar.txt': null }
}) // remove subdir/bar.txt
fixturify.readSync('testdir') // => { foo.txt: 'foo.text contents' }
fixturify.writeSync('testDir', {
'subdir': null
}) // remove subdir/
const fs = require('fs')
const fixturify = require('fixturify')
const obj = {
'subdir': {
'foo.txt': 'foo.txt contents'
},
'emptydir': {}
}
fixturify.writeSync('testdir', obj) // write it to disk
fixturify.readSync('testdir', { ignoreEmptyDirs: true })
// => { subdir: { foo.txt': 'foo.txt contents' } }
File contents are decoded and encoded with UTF-8.
fixture.readSync
follows symlinks. It throws an error if it encounters a
broken symlink.
To keep the API simple, node-fixturify has the following limitations:
Reading or setting file stats (last-modified time, permissions, etc.) is not supported.
Creating symlinks is not supported. Symlinks are traversed when reading. Broken symlinks throw.
Special files like FIFOs, sockets, or devices are not supported.
File contents are automatically encoded/decoded into strings. Binary files are not supported.
FAQs
Convert objects into directory structures and back again
We found that fixturify demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.